/**
 * 后台用户管理 JS
 */
$(function(){

});

$('.table-sort').dataTable({
	"aaSorting": [[ 1, "desc" ]],//默认第几个排序
	"bStateSave": true,//状态保存
	"aoColumnDefs": [
	  //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
	  {"orderable":false,"aTargets":[0,5]}// 不参与排序的列
	]
});

/**
 * 添加后台用户
 */
function add_user(title,url,w,h){
	layer_show(title,url,w,h);
}

/*后台用户-删除*/
function user_del(obj,id){
	layer.confirm('确认要删除吗？',function(index){
		$.ajax({
			type : "delete",
			dataType : "json",
			url:"delete/"+id+".do",
			success : function(data) {
				if (data.status == "success") {
					$(obj).parents("tr").remove();
					layer.msg(data.message,{icon:1});
				} else {
					layer.msg(data.message,{icon:2});
				}
			}
		});
	});
}

/**
 * 启用||停用
 * @param obj
 * @param id
 * @param status
 */
function chang_user(obj,id,status){
	var _this = $(obj);
	var optHtml = "";
	var statusHtml = "";
	var text = "";
	if(status == "true"){
		optHtml = "<a style='text-decoration:none' onClick=\"chang_user(this,'"+id+"','false')\" href='javascript:;' title='停用'><i class='Hui-iconfont'>&#xe631;</i></a>";
		statusHtml = "<span class='label label-success radius'>已启用</span>";
		text = "启用成功!";
	}else{
		optHtml = "<a style='text-decoration:none' onClick=\"chang_user(this,'"+id+"','true')\" href='javascript:;' title='启用'><i class='Hui-iconfont'>&#xe615;</i></a>";
		statusHtml = "<span class='label radius'>已停用</span>";
		text = "停用成功!";
	}
	$.ajax({
		type : "put",
		dataType : "json",
		url:"update_status/"+id+".do",
		success : function(data) {
			if (data.status == "success") {
				_this.replaceWith(optHtml);
				$(".td-status"+id).html(statusHtml);
				layer.msg(text,{icon:1});
			} else {
				layer.msg(data.message,{icon:2});
			}
		}
	});
}

/*后台用户-编辑*/
function user_edit(){
	
}
